<template xmlns="http://www.w3.org/1999/html">
  <el-dialog :title="title" :visible.sync="expend" width="30%">
    <!--新建-->
    <smart-form ref="form_create" method="POST" url="/sys/org/info"
                v-show="operation==='new'" :on-succeed="callback">
      <smart-form-layout require name="id" label="ID">
        <smart-text-view name="id" placeholder="ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="shortName" label="简称">
        <smart-text-view name="shortName" placeholder="简称"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="organizationName" label="机构名称">
        <smart-text-view name="organizationName" placeholder="机构名称"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="provinceId" label="省ID">
        <smart-text-view name="provinceId" placeholder="省ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="cityId" label="市ID">
        <smart-text-view name="cityId" placeholder="市ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="countyId" label="县ID">
        <smart-text-view name="countyId" placeholder="县ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="description" label="描述">
        <smart-text-view name="description" placeholder="描述"></smart-text-view>
      </smart-form-layout>
    </smart-form>

    <!--更新-->
    <smart-form ref="form_modify" method="PUT" url="/sys/org/info"
                v-show="operation==='edit'" :on-succeed="callback">
      <smart-form-layout require name="id" label="ID">
        <smart-text-view name="id" placeholder="ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="shortName" label="简称">
        <smart-text-view name="shortName" placeholder="简称"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="organizationName" label="机构名称">
        <smart-text-view name="organizationName" placeholder="机构名称"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="provinceId" label="省ID">
        <smart-text-view name="provinceId" placeholder="省ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="cityId" label="市ID">
        <smart-text-view name="cityId" placeholder="市ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="countyId" label="县ID">
        <smart-text-view name="countyId" placeholder="县ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="description" label="描述">
        <smart-text-view name="description" placeholder="描述"></smart-text-view>
      </smart-form-layout>
    </smart-form>

  </el-dialog>
</template>

<script>


export default {
    components: {},
    props: {
        // 成功回调，通常是刷新数据表格
        onSucceed: {type: Function, default: undefined}
    },
    data() {
        return {
            // 是否展开弹出层
            expend: false,
            // 当前操作的数据
            row_data: undefined,
            // 操作名称
            operation: undefined,
            // 弹窗名称
            title: ''
        }
    },
    methods: {
        /**
         * 新增/编辑操作成功，关闭当前窗口
         *
         * @param ret 后台响应数据
         */
        callback: function (ret) {
            if (this.onSucceed !== undefined) {
                this.onSucceed(ret)
            }
        },
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        onAction: function (evt, row, old) {
            switch (evt) {
                case 'edit':
                    let row_data = row;
                    this.operation = evt;
                    this.title = `更新`;
                    this.expend = true;
                    this.row_data = row_data;
                    break;
                case 'new':
                    this.operation = evt;
                    this.title = `新建`;
                    this.expend = true;
                    break;
            }
        }
    }
}
</script>
